package com.qky.dao.regionDao;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.qky.dao.utilDao.CurrentSessionDao;
import com.qky.model.region.City;
import com.qky.model.region.County;
import com.qky.model.region.Province;

@Repository
public class RegionDao extends CurrentSessionDao {
	
	/**
	 * 用来查询三级联动
	 * @param regionID
	 * @return
	 */
	public List getRegionListByParent(String regionId) {
		Criteria criteria = null;
		String propertyName = null,value;
		System.out.println(regionId);
		regionId=regionId.replaceAll("0*$","");
		if (regionId.length()==4) {
			propertyName="regionId";
			criteria=currentSession().createCriteria(County.class);
		}else if(regionId.length()==2){
			propertyName="regionId";
			criteria=currentSession().createCriteria(City.class);
		}else {
			propertyName="provinceId";
			criteria=currentSession().createCriteria(Province.class);
		}
		value=regionId+"%";
		List list=criteria.add(Restrictions.like(propertyName, value)).list();
		return list;
	}
	
	/*public List getRegionListByRegion(String regionID) {
		
	}*/
}
